<@override name="content">
  <div class="pagination pagination-centered">
    <div class="form-inline">
      <form class="form-search" action="status">
        <input type="number" class="input-small" name="pid" value="${pid!}" min="1000" placeholder="Problem ID">
        <input type="text" class="input-small" name="name" value="${name!}" placeholder="User Name">
        <select class="input-medium" id="inputLanguage" name="language">
          <option value="0">Language</option> 
          <#if program_languages??> 
          <#list program_languages.keySet() as key>
          <option value="${key!}"<#if language?? && language==key>selected</#if>>${program_languages.get(key)!}</option> 
          </#list> 
          </#if>
        </select>
        <select class="input-small" id="inputResult" name="result">
          <option value="-1">Result</option> 
          <#if judge_result??> 
          <#list judge_result as Result>
          <#if Result.id<=9>
          <option value="${Result.id!}" <#if result?? && result?eval==Result.id>selected</#if>>${Result.name!}</option>
          </#if>
          </#list> 
          <option value="999" <#if result?? && result?eval==999>selected</#if>>Not-AC</option>
          </#if>
        </select> 
        <button type="submit" class="btn btn-info">Go</button>
      </form>
    </div>
    
    <#include "../common/_paginate.html" />
    <@paginate currentPage=solutionList.pageNumber totalPage=solutionList.totalPage actionUrl="status/" urlParas="?${query!}"/>
    
    <div class="pull-right">
      <span class="badge badge-info">${solutionList.pageNumber}/${solutionList.totalPage} Pages</span>
      <span class="badge badge-info">${solutionList.totalRow} Records</span>
    </div>
  </div>

  <table id="status" class="table table-hover table-condensed">
    <thead>
      <tr>
        <th>Run ID</th>
        <th>User</th>
        <th>Problem</th>
        <th>Result</th>
        <th>Time</th>
        <th>Memory</th>
        <th>Language</th>
        <th>Code Length</th>
        <th>Submit Time</th>
      </tr>
    </thead>
    <tbody>
      <#if solutionList??> 
      <#list solutionList.list as solution>
      <tr>
        <td class="sid">${solution.sid!}</td>
        <td class="user"><a href="user/profile/${(solution.name)!}" class="name">${(solution.name)!}</a></td>
        <td class="problem">
        <#if !adminUser?? && solution.alpha??> 
        <a href="contest/problem/${solution.cid}-${solution.alpha!}">${solution.cid}-${solution.alpha!}</a>
        <#else> 
        <a href="problem/show/${solution.pid!}">${solution.pid!}</a> 
        <#if solution.alpha??> <a href="contest/problem/${solution.cid}-${solution.alpha!}">${solution.cid}-${solution.alpha!}</a></#if> 
        </#if>
        </td>
        <td class="result" id="${solution.resultName!}" sid="${solution.sid!}">${solution.resultLongName!}</td>
        <td class="time"><#if solution.result==0>${solution.time!0} MS</#if></td>
        <td class="memory"><#if solution.result==0>${solution.memory!0} KB</#if></td>
        <td class="language"><#if user?? &&(adminUser?? || user.uid==solution.uid)><a href="code/${solution.sid!}" target="_blank" title="show source code"></#if>
            ${solution.languageName!} <#if user?? &&(adminUser?? || user.uid==solution.uid)></a></#if>
        </td>
        <td class="code_len">${solution.codeLen!} B</td>
        <td class="ctime">${solution.ctime_t!}</td>
      </tr>
      </#list> 
      </#if>
    </tbody>
  </table>
</@override>

<@override name="scripts">
  <script type="text/javascript">
    $(document).ready(function() {
      var prevpage = "status/${solutionList.pageNumber-1}?${query!}";
      var nextpage = "status/${solutionList.pageNumber+1}?${query!}";
      $(document).keydown(function(event) {
        <#if (solutionList.pageNumber>1)>if (event.keyCode == 37)window.location = prevpage;</#if>
        <#if solutionList.pageNumber<solutionList.totalPage>if (event.keyCode == 39)window.location = nextpage;</#if>
      });
      
      var refresh = setInterval(function(){refreshResult();}, 1500);
      setTimeout(function() {clearInterval(refresh);}, 20010);
     
      function refreshResult()
      {
          $('#WAIT, #RUN').each(function() {
            var $this = $(this);
            var id = $this.attr('id');
            $.getJSON('api/problem/getResult', {'sid': $this.attr('sid')}, function(data) {
              if (data.result.name != id) {
                $this.attr('id', data.result.name);
                $this.html(data.result.longName);
                if (data.result.name == 'AC') {
                  $this.siblings('.time').html(data.time + ' MS');
                  $this.siblings('.memory').html(data.memory + ' KB');
                }
              }
            });
        });
      }
    });
  </script>
</@override>
<@extends name="../common/_layout.html" />
